package com.xc.quickstart.common.util;

import com.github.rholder.retry.Retryer;
import com.github.rholder.retry.RetryerBuilder;
import com.github.rholder.retry.StopStrategies;
import com.github.rholder.retry.WaitStrategies;
import com.xc.quickstart.common.exception.CommonBizException;
import feign.FeignException;

import java.io.IOException;
import java.util.Objects;
import java.util.concurrent.TimeUnit;

public class RetryUtil {
    private static final Retryer<Boolean> retryer = RetryerBuilder.<Boolean>newBuilder()
            .retryIfResult(Objects::isNull)
            .retryIfExceptionOfType(IOException.class)
            .retryIfExceptionOfType(FeignException.class)
            .retryIfExceptionOfType(CommonBizException.class)
            .withStopStrategy(StopStrategies.stopAfterAttempt(3))
            .withWaitStrategy(WaitStrategies.fixedWait(3, TimeUnit.SECONDS))
            .build();

    public static Retryer<Boolean> getRetryer() {
        return retryer;
    }

}
